#!/bin/bash
cd ~/app-root/data/github-sh/pkg/firefox/
if grep "$(grep -o '^[0-9]\{2\}' ~/app-root/data/temp/firefox/oldbeta)" ~/app-root/data/temp/firefox/oldre; then
grep -o "^[0-9\.]\{4,7\}" ~/app-root/data/temp/firefox/oldre > pkgver.txt
sed 's#.*\([0-9]\{1,2\}\)$#\1#'  ~/app-root/data/temp/firefox/oldre >build.txt
else
grep -o "[0-9]\{2,3\}.0b[0-9]\{1,2\}" ~/app-root/data/temp/firefox/oldbeta > pkgver.txt
sed 's#.*\([0-9]\{1,2\}\)$#\1#'  ~/app-root/data/temp/firefox/oldbeta >build.txt
fi
if ! grep -q $(cat pkgver.txt)'$' ~/app-root/data/temp/pkg/tmp/firefox-beta-zh-cn/PKGBUILD;then
differ=0
fi
if ! grep -q pkgrel=$(cat build.txt) ~/app-root/data/temp/pkg/tmp/firefox-beta-zh-cn/PKGBUILD;then
differ=0
fi
if [ $differ == "0" ];then
sed -i -e "/pkgver=/c\pkgver=$(cat pkgver.txt)" -e "/pkgrel=/s#[0-9]\{1,2\}#$(cat build.txt)#" ~/app-root/data/temp/pkg/firefox-beta-zh-cn/PKGBUILD
sed -i -e "/pkgver =/c\pkgver = $(cat pkgver.txt)" -e "/pkgrel/s#[0-9]\{1,2\}#$(cat build.txt)#" ~/app-root/data/temp/pkg/firefox-beta-zh-cn/.SRCINFO
fi
rm -f *.txt
cd ~/app-root/data/temp/pkg/
diff -q firefox-beta-zh-cn/ tmp/firefox-beta-zh-cn/ | sed -e 's#Files ##' -e 's#and.*differ##' >diff.txt
zip pkg.zip -r $(cat diff.txt)
rm -rf firefox-beta-zh-cn/ ~/app-root/data/github-sh/pkg/firefox/*.txt